define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'editable'], function ($, undefined, Backend, Table, Form, undefined) {
    if(Config.product_id == '' || Config.product_id == null){
        Config.product_id = 0;
    }
    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'feditionorderskup/index/?product_id=' + Config.product_id,
                    add_url: 'feditionorderskup/add/?product_id=' + Config.product_id,
                    edit_url: 'feditionorderskup/edit',
                    del_url: 'feditionorderskup/del',
                    multi_url: 'feditionorderskup/multi',
                    import_url: 'feditionorderskup/import',
                    table: 'fedition_ordersku',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search:false,
                searchFormVisible: true,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'accounturl', title: __('Accounturl'),visible: false,addClass: "selectpage", extend: "data-source='feditionaccounturl/index' data-field='name'"},
                        {field: 'accounturl_name', title: __('Accounturl'), operate:false},
                        {field: 'sku', title: __('Sku'),editable: true, operate: 'LIKE'},
                        {field: 'variants_id', title: __('变体id'), operate:'LIKE'},
                        {field: 'material', title: __('Material'),editable: true,operate:'BETWEEN'},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'product_name', title: __('商品名称'), operate: 'LIKE'},
                        // {field: 'product_id', title: __('商品id'), operate: 'LIKE'},
                        // {field: 'status', title: __('Status'), searchList: {"normal":__('Normal'),"hidden":__('Hidden')}, formatter: Table.api.formatter.status},
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
            $("#c-accounturl").data("formatItem",function (item) {
                return "店铺名称:"+item.name+",店铺域名:"+item.url;
            });
        },
        edit: function () {
            Controller.api.bindevent();
            $("#c-accounturl").data("formatItem",function (item) {
                return "店铺名称:"+item.name+",店铺域名:"+item.url;
            });
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});